var t = getApp();

Page({
    data: {
        components: [],
        page_id: "",
        page_info: {},
        btnFlag: !1,
        current_page: 1,
        total_page: 0,
        decorate_isLoadMore: !0,
        bottomShowBol: !1,
        bottomShowBolIndex: 0,
        showPage: !1,
        isWatch: !0,
        fullShow: !1,
        full_screen: {},
        advertising: {},
        popShow: !1,
        footshow: !1,
        foot_type: "",
        bottom_info: {},
        top_info: {}
    },
    onLoad: function(a) {
        a.page_id && this.setData({
            page_id: a.page_id
        }), a.mid && t._setMid(a.mid), this.getCPSdata();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.getCPSdata();
    },
    onReachBottom: function() {
        this.setData({
            bottomShowBol: !0
        }), this.data.decorate_isLoadMore && this.getMoreDecorate();
    },
    onShareAppMessage: function() {
        var t, a = wx.getStorageSync("yz_uid"), e = "";
        return a && (e = a), {
            title: (null === (t = this.pageShare) || void 0 === t ? void 0 : t.page_title) || "",
            path: "/packageG/cps/cpsPage/cpsPage?page_id=".concat(this.data.page_id, "&mid=").concat(e)
        };
    },
    onPageScroll: function(t) {
        t.scrollTop > 80 ? this.data.btnFlag || this.setData({
            btnFlag: !0
        }) : this.data.btnFlag && this.setData({
            btnFlag: !1
        }), this.data.bottomShowBol && this.setData({
            bottomShowBol: !1
        });
    },
    getCPSdata: function() {
        var a = this;
        this.setData({
            showPage: !1
        }), wx.showLoading({
            title: "加载中"
        });
        var e = {
            page_id: this.data.page_id
        }, i = t.getNetAddresss("home-page.index");
        t._getNetWork({
            url: i,
            data: e,
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    if (e.data.item) {
                        a.setData({
                            showPage: !0
                        }), wx.stopPullDownRefresh({
                            complete: function(t) {
                                console.log("关闭下拉刷新", t, new Date());
                            }
                        });
                        var i = e.data.item.pageinfo ? e.data.item.pageinfo.params : {};
                        a.setData({
                            components: e.data.item.datas,
                            page_name: e.data.item.page_info.page_title,
                            decorate_isLoadMore: !0,
                            footshow: !0,
                            foot_type: e.data.item.foot_type,
                            isWatch: 0 != i.allowauth
                        }), !a.data.isWatch && e.data.item.page_info.member_level_url && e.data.item.page_info.member_level_url.link && e.data.item.page_info.member_level_url.link.indexOf("packageG/index/index") < 0 && wx.redirectTo({
                            url: e.data.item.page_info.member_level_url.link
                        }), e.data.item.page && a.setData({
                            total_page: e.data.item.page.total_page,
                            current_page: e.data.item.page.current_page,
                            bottomShowBolIndex: e.data.item.page.count - 1
                        }), wx.setNavigationBarTitle({
                            title: a.data.page_name
                        }), e.data.item.page_info && (a.setData({
                            advertising: e.data.item.page_info.advertising_id || {},
                            full_screen: e.data.item.page_info.full_screen_id || {}
                        }), a.data.advertising.id && a.data.advertising.datas && (a.data.advertising.datas = JSON.parse(a.data.advertising.datas), 
                        a.setData({
                            advertising: a.data.advertising
                        }))), a.setPageADData(), a.setFootData(e.data.item), a.pageShare = {
                            page_title: e.data.item.page_info.page_title
                        }, e.data.item.page_info && e.data.item.page_info.preview_color && wx.setNavigationBarColor({
                            backgroundColor: e.data.item.page_info.preview_color,
                            frontColor: 1 == e.data.item.page_info.font_color ? "#ffffff" : "#000000",
                            animation: {
                                duration: 400,
                                timingFunc: "easeIn"
                            }
                        });
                    }
                } else wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
                wx.hideLoading();
            }
        });
    },
    setFootData: function(t) {
        var a = {}, e = {};
        t.top && t.top.id && (a = JSON.parse(t.top.page_info)), 1 == t.foot_type ? t.foot && t.foot.page_info && (e = JSON.parse(t.foot.page_info)) : 2 == t.foot_type && (e = t.foot instanceof Array ? {} : JSON.parse(t.foot.page_info)), 
        this.setData({
            top_info: a,
            bottom_info: e
        });
    },
    setPageADData: function() {
        var t = this, a = wx.getStorageSync("fullAdvertisement");
        this.data.full_screen && this.data.full_screen.id && !a && 1 === this.data.full_screen.show_rule && (wx.setStorageSync("fullAdvertisement", !0), 
        this.setData({
            fullShow: !0
        }), setTimeout(function() {
            t.countDown(t.data.full_screen.show_time);
        }, 2e3));
        var e = wx.getStorageSync("fullAdvertisement_expiration"), i = parseInt(Date.parse(new Date()) / 1e3);
        if (this.data.full_screen && this.data.full_screen.id && 2 === this.data.full_screen.show_rule && e < i) {
            var o = parseInt((new Date(new Date().toLocaleDateString()).getTime() + 864e5 - 1) / 1e3);
            wx.setStorageSync("fullAdvertisement_expiration", o), this.setData({
                fullShow: !0
            }), setTimeout(function() {
                t.countDown(t.data.full_screen.show_time);
            }, 2e3);
        }
        var n = wx.getStorageSync("popAdvertisement");
        this.data.advertising && this.data.advertising.id && !n && 1 === this.data.advertising.show_rule && (wx.setStorageSync("popAdvertisement", !0), 
        this.setData({
            popShow: !0
        }));
        var s = wx.getStorageSync("popAdvertisement_expiration"), r = parseInt(Date.parse(new Date()) / 1e3);
        if (this.data.advertising && this.data.advertising.id && 2 === this.data.advertising.show_rule && s < r) {
            var d = parseInt((new Date(new Date().toLocaleDateString()).getTime() + 864e5 - 1) / 1e3);
            wx.setStorageSync("popAdvertisement_expiration", d), this.setData({
                popShow: !0
            });
        }
    },
    turnFullTo: function() {
        var t = this.data.full_screen.minapp_link;
        try {
            wx.navigateTo({
                url: t
            });
        } catch (t) {
            wx.showToast({
                title: "链接设置错误",
                icon: "none",
                duration: 2e3
            });
        }
    },
    closeFull: function() {
        this.setData({
            fullShow: !1
        });
    },
    turnTo: function() {
        if (2 == this.data.advertising.is_minapp) if (this.data.advertising.minapp_sid) if (this.data.advertising.minapp_link2) try {
            wx.navigateToMiniProgram({
                appId: this.data.advertising.minapp_sid,
                path: this.data.advertising.minapp_link2,
                extraData: {},
                envVersion: "release",
                success: function(t) {},
                fail: function(t) {
                    wx.showToast({
                        title: "小程序跳转失败",
                        icon: "none",
                        duration: 2e3
                    });
                }
            });
        } catch (t) {
            wx.showToast({
                title: "小程序跳转失败",
                icon: "none",
                duration: 2e3
            });
        } else wx.showToast({
            title: "请设置跳转小程序后的跳转链接",
            icon: "none",
            duration: 2e3
        }); else wx.showToast({
            title: "请设置小程序所需跳转appId",
            icon: "none",
            duration: 2e3
        }); else {
            var t = this.data.advertising.minapp_link;
            try {
                wx.navigateTo({
                    url: t
                });
            } catch (t) {
                wx.showToast({
                    title: "链接设置错误",
                    icon: "none",
                    duration: 2e3
                });
            }
        }
    },
    closePop: function() {
        this.setData({
            popShow: !1
        });
    },
    countDown: function(t) {
        var a = this, e = t;
        this.setData({
            "full_screen.show_time": e,
            "advertisement.time": e
        }), e--;
        var i = setTimeout(function() {
            e <= 0 ? (a.setData({
                fullShow: !1
            }), clearInterval(i)) : a.countDown(e);
        }, 1e3);
    },
    getMoreDecorate: function() {
        var a = this;
        if (this.setData({
            decorate_isLoadMore: !1
        }), this.data.current_page < this.data.total_page) {
            this.setData({
                current_page: this.data.current_page + 1
            });
            var e = t.getNetAddresss("plugin.decorate.frotend.decorate-api.get-page");
            t._postNetWork({
                url: e,
                data: {
                    decorate_page: this.data.current_page,
                    decorate_id: this.data.page_id
                },
                success: function(t) {
                    var e = t.data;
                    1 == e.result ? a.setData({
                        decorate_isLoadMore: !0,
                        components: a.data.components.concat(e.data.datas)
                    }) : a.setData({
                        decorate_isLoadMore: !1,
                        current_page: a.data.current_page - 1
                    });
                }
            });
        }
    }
});